﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Json;

namespace PC_Client
{
    public class Common
    {
        private static readonly Unit _unit = new Unit();

        public static void CloseSocket(Socket socket, string name)
        {
            _unit.MsgSend = new byte[65535];
            MessagePackage mp = new MessagePackage { ConnectType = (int)ConnectType.Exit, Name = name, Msg = name };
            _unit.MsgSend = Encoding.UTF8.GetBytes(JsonSerializer<MessagePackage>.GetObjectToJson(mp));
            socket.Send(_unit.MsgSend);

            socket.Shutdown(SocketShutdown.Both);
            socket.Disconnect(false);
            socket.Close();
        }
    }
}
